package practise.SudokuChecker;

import java.io.BufferedInputStream;
import java.io.IOException;

public class Bate1
{
	private static BufferedInputStream in = new BufferedInputStream(System.in);
	
	public static void main(String[] args) throws IOException
	{
		int n = readInt()+1;
		for(int i=1; i<n; i++)
		{
			handel(i);
		}
	}
	
	private static void handel(int c) throws IOException
	{
		int n = readInt();
		int s = n*n;
		int sum = s*(s+1)/2;
		
		int[][] nums = new int[s][s];
		boolean flag = false;
		
		for(int i=0; i<s; i++)
		{
			for(int j=0; j<s; j++)
			{
				nums[i][j] = readInt();
				
				if(nums[i][j] > s)
				{
					flag = true;
				}
			}
		}
		
		if(flag)
		{
			System.out.println("Case #" + c + ": No");
			return;
		}
			
		
		for(int i=0; i<s; i++)
		{
			int s1 = 0;
			int s2 = 0;
			int s3 = 0;
			
			for(int j=0; j<s; j++)
			{	
				s1 += nums[j][i];
				s2 += nums[i][j];
				s3 += nums[i/n*n+j/n][i%n*n+j%n];
			}
			
			if(s1 != sum || s2 != sum || s3 != sum)
			{
				System.out.println("Case #" + c + ": No");
				return;
			}
		}
		
		System.out.println("Case #" + c + ": Yes");
	}

	private static int readInt() throws IOException
	{
		int i,sum=0;
		
		while(((i=in.read())&48) != 48 || i>57);
		
		for(;(i&56) == 48 || (i&62) == 56; i=in.read())
			sum = sum*10 + (i&15);
		
		return sum;
	}
}
